import collections


class Solution:
    def minKnightMoves(self, x: int, y: int) -> int:
        ans = 0
        visited = {(0, 0)}
        queue = collections.deque([(0, 0)])
        while queue:
            for _ in range(len(queue)):
                x1, y1 = queue.popleft()
                if (x1, y1) == (x, y):
                    return ans
                for x2, y2 in [(x1 + 2, y1 - 1), (x1 + 2, y1 + 1), (x1 + 1, y1 + 2), (x1 + 1, y1 - 2), (x1 - 1, y1 + 2),
                               (x1 - 1, y1 - 2), (x1 - 2, y1 - 1), (x1 - 2, y1 + 1)]:
                    if (x2, y2) not in visited:
                        visited.add((x2, y2))
                        queue.append((x2, y2))

            ans += 1


if __name__ == "__main__":
    print(Solution().minKnightMoves(x=2, y=1))  # 1
    print(Solution().minKnightMoves(x=5, y=5))  # 4
